# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError


class StockProductionLot(models.Model):
    _inherit = 'stock.production.lot'

    @api.model
    def get_lot_move_line(self, res_id):
        """widget使用：批次返回对于的出入库明细"""
        lot = self.browse(res_id)
        move_lines = self.env['stock.move.line'].search([('lot_id', '=', lot.id)])
        tree = self.env.ref('stock.view_move_line_tree')
        form = self.env.ref('stock.view_move_line_form')
        domain = [('id', 'in', move_lines.ids)]
        action = {
            'type': 'ir.actions.act_window',
            'views': [(tree.id, 'list'), (form.id, 'form')],
            'view_mode': 'list,form',
            'name': _('移动明细'),
            'res_model': 'stock.move.line',
            'domain': domain
        }
        return action
